<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@taglib prefix="sec"
	uri="http://www.springframework.org/security/tags"%>


<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${applicationScope.KEY_SITE_NAME}</title>
<link href="resources/css/jquery-ui.css" rel="stylesheet"
	type="text/css" />
<link href="resources/css/jquery.dataTables.css" rel="stylesheet"
	type="text/css" />
<link href="resources/css/intstyle.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="resources/scripts/jquery-1.9.1.js"></script>
<script type="text/javascript"
	src="resources/scripts/jquery-ui.custom.js"></script>
<script type="text/javascript"
	src="resources/scripts/jquery.dataTables.js"></script>
<script type="text/javascript" src="resources/scripts/common.js"></script>

<script type="text/javascript">
<!--
var tableObj;
	$(document).ready(function() {

		renderButtons();
		changeSideMenuBackColor("sideMenuGameList");

		tableObj = getDataTable("gameTable", dataTableLabels, 20);

		$("#gameInfoDialog").dialog({
			modal : true,
			autoOpen : false,
			width : 400,
			height : 550,
			open : function(event, ui) {
				$(".ui-dialog-titlebar").show();
			},
			buttons : [ {
				text : "<spring:message code='Label.dialog.ok'/>",
				click : function() {
					$(this).dialog("close");
				}
			} ]
		});

	});
	
function viewGameInfo(action,rowId) {

	$.post(encodeURI(action), function(obj,
			status) {
		
		
		$("#typeValue").html(obj.typeStr);
		$("#nameValue").html(obj.name);
		$("#keywordsValue").html(obj.keywords);
		$("#orgValue").html(obj.company);
		$("#urlValue").html(obj.url);
		$("#downloadValue").html(obj.downloadMethod);
		$("#startDateValue").html(obj.startDtStr);
		$("#coseValue").html(obj.cost);
		$("#produceValue").html(obj.produceMethod);
		$("#popularityValue").html(obj.popularity);
		$("#feasibilityValue").html(obj.feasibility);
		$("#gameimg").attr("src","fileupload/gamelogo/" + obj.logoUrl);			

		$("#gameInfoDialog").dialog({
			modal : true,
			autoOpen : false,
			width : 600,
			height: 680,
			open : function(event, ui) {
				$(".ui-dialog-titlebar").show();
			},
			buttons: [
						{
							text: "<spring:message code='Label.dialog.ok'/>",
							click: function() {
								$(this).dialog("close");								
							}
						}
					]
		}).dialog("open");
	}); 
}



function updateGameStatus(action, row) {

	$.post(encodeURI(action), function(obj,
			status) {
		if (obj.accessDenied) {
			showInfoDialog("error","<spring:message code='msg.error.failed.update'/>");
		} else if (obj.cause == "1") {
			$("tr[id="+ row +"]").find("td").eq(4).html("<spring:message code='Label.common.status.active'/>");
		} else if (obj.cause == "0") {
			$("tr[id="+ row +"]").find("td").eq(4).html("<spring:message code='Label.common.status.inactive'/>");
		} else if (obj.cause == "-1") {
			/* $("tr[id="+ row +"]").remove();	 */
			tableObj.fnDeleteRow($("tr[id="+ row +"]"));
		}
	}); 
}

function confirmDeleteAction(action,row) {
	showConfirmDialog("<spring:message code='msg.dialog.confirm.delete'/>", function(result){
		if (result == true) {
			updateGameStatus(action,row);
		} else {
			return;
		}		
	});
}
	
//-->
</script>

<!--[if lte IE 7]>
<style>
.content { margin-right: -1px; } /* 此 1px 负边距可以放置在此布局中的任何列中，且具有相同的校正效果。 */
ul.nav a { zoom: 1; }  /* 缩放属性将为 IE 提供其需要的 hasLayout 触发器，用于校正链接之间的额外空白 */
</style>
<![endif]-->
</head>

<body>

	<div class="container">
		<%@include file="../../header.jsp"%>
		<%@include file="../sidebar.jsp"%>
		<div id="contentBoxDiv" class="content">
			<div class="subnav">
				<spring:message code="Label.menu.headnav.goods" />
				&gt;&gt;
				<spring:message code="Label.menu.game.main" />
				&gt;&gt;
				<spring:message code="Label.menu.game.list" />
			</div>
			<%@include file="../../errorMessagePanel.jsp"%>
			<div class="box">
				<h2>
					<spring:message code="Label.menu.game.list" />
				</h2>
				<div class="box" style="border: none;">
					<table id="gameTable" width="100%">
						<thead>
							<tr>
								<th ><spring:message code="Label.common.SN" /></th>
								<th ><spring:message code="Label.game.name" /></th>
								<th ><spring:message code="Label.game.keywords" /></th>
								<th ><spring:message code="Label.game.url" /></th>
								<th ><spring:message code="Label.game.status" /></th>
								<th ><spring:message code="Label.common.action" /></th>
							</tr>
						</thead>
						<tbody>

							<c:if test="${not empty games}">
								<c:forEach items="${games}" var="game" varStatus="status">
										<tr id="tr${status.index}">
										<td>${status.index+1}</td>
										<td>${game.name}</td>
										<td>${game.keywords}</td>
										<td>${game.url}</td>
										<td><c:if test="${-1 == game.status}">
												<spring:message code="Label.common.status.delete"></spring:message>
											</c:if> <c:if test="${0 == game.status}">
												<spring:message code="Label.common.status.inactive"></spring:message>
											</c:if> <c:if test="${1 == game.status}">
												<spring:message code="Label.common.status.active"></spring:message>
											</c:if></td>
										<td>
										<div style="width:210px;">
										<button class="tableButton" onclick="viewGameInfo('admin/game/view/${game.gameId}')">
												<spring:message code="Label.game.view" /></button> 
											<button class="tableButton editbutton" onclick="window.location.href='<%=basePath%>admin/game/edit/${game.gameId}'">
												<spring:message code="Label.game.edit" /></button> 
											<button class="tableButton activebutton" onclick="updateGameStatus('admin/game/status/update/${game.gameId}/1','tr${status.index}')">
												<spring:message	code="Label.common.status.active" /></button> 
											<button class="tableButton activebutton"  onclick="updateGameStatus('admin/game/status/update/${game.gameId}/0','tr${status.index}')">
												<spring:message	code="Label.common.status.inactive" /></button> 
											<button	class="tableButton deletebutton" onclick="confirmDeleteAction('admin/game/status/update/${game.gameId}/-1','tr${status.index}')">
												<spring:message code="Label.common.status.delete" /></button>
										</div>
										</td>
									</tr>
								</c:forEach>
							</c:if>
						</tbody>
						<tfoot>
							<tr>
								<th><spring:message code="Label.common.SN" /></th>
								<th><spring:message code="Label.game.name" /></th>
								<th><spring:message code="Label.game.keywords" /></th>
								<th><spring:message code="Label.game.url" /></th>
								<th><spring:message code="Label.game.status" /></th>
								<th><spring:message code="Label.common.action" /></th>
							</tr>
						</tfoot>
					</table>



				</div>
			</div>
			<div id="gameInfoDialog"
				title="<spring:message code='Label.user.internal.info.title'/>"
				style="dispaly: none;">

				<table class="infoTable" cellpadding="5" cellspacing="10" border="0">
					<tr>
						<td><label><spring:message	code="Label.game.type" />:</label></td>
						<td><label id="typeValue"></label></td>
					</tr>
					<tr>
						<td><label><spring:message code="Label.game.name"/>:</label></td>
						<td><label id="nameValue"></label></td>
					</tr>
					<tr>
						<td><label><spring:message code="Label.game.keywords"/>:</label></td>
						<td><label id="keywordsValue"></label></td>
					</tr>
					<tr>
						<td><label><spring:message code="Label.game.org"/>:</label></td>
						<td><label id="orgValue"></label></td>
					</tr>
					<tr>
						<td><label><spring:message code="Label.game.url"/>:</label></td>
						<td><label id="urlValue"></label></td>
					</tr>
					<tr>
						<td><label><spring:message code="Label.game.download"/>:</label></td>
						<td><label id="downloadValue"></label></td>
					</tr>
					<tr>
						<td><label><spring:message code="Label.game.startDate"/>:</label></td>
						<td><label id="startDateValue"></label></td>
					</tr>
					<tr>
						<td><label><spring:message code="Label.game.cost"/>:</label></td>
						<td><label id="coseValue"></label></td>
					</tr>
					<tr>
						<td><label><spring:message code="Label.game.produceMethod"/>:</label></td>
						<td><label id="produceValue"></label></td>
					</tr>
					<tr>
						<td><label><spring:message code="Label.game.popularity"/>:</label></td>
						<td><label id="popularityValue"></label><spring:message code="Label.game.rank"/></td>
					</tr>
					<tr>
						<td><label><spring:message code="Label.game.feasibility"/>:</label></td>
						<td><label id="feasibilityValue"></label><spring:message code="Label.game.rank"/></td>
					</tr>
					<tr>
						<td><label><spring:message code="Label.game.logo"/>:</label></td>
						<td><img id="gameimg" height='80' width='200'/></td>
					</tr>

				</table>
			</div>
			<!-- end .content -->
		</div>
		<div class="clearfloat" />
		<%@include file="../../footer.jsp"%>
		<!-- end .container -->
	</div>
</body>
</html>